import { Button, Modal } from 'antd';
import { useState, useEffect } from 'react';
function ModalBox(props) {
    const [isModalOpen, setIsModalOpen] = useState(false);
    // 打开对话框
    const showModal = () => {
        setIsModalOpen(true);
    };
    // 点击确定
    const handleOk = () => {
        setIsModalOpen(false);
    };
    // 点击取消
    const handleCancel = () => {
        setIsModalOpen(false);
    };
    useEffect(() => {
        props.showModal ? showModal() : handleCancel()
    }, [props.showModal])
    return(
        <>
            <div type="primary" onClick={showModal}>
                {props.children[0]}
            </div>
            <Modal title={props.title} open={isModalOpen} onOk={handleOk} onCancel={handleCancel} footer={props.children[2]}>
                {props.children[1]}
            </Modal>
        </>
    )
}

export default ModalBox